package com.rykj.qxj.test.redisTest;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.http.codec.multipart.SynchronossPartHttpMessageReader;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.Tuple;

public class Redis {
	
     public static void main(String[] args) {
    	 Jedis jedis = new Jedis("127.0.0.1", 6379);
    	 System.out.println(jedis);
    	/* jedis.zincrby("zkey", 1, "aa");
    	 jedis.zincrby("zkey", 1, "bb");
    	 jedis.zincrby("zkey", 1, "cc");
    	 jedis.zincrby("zkey", 1, "dd");
    	 jedis.zincrby("zkey", 1, "ee");
    	 System.out.println(jedis.zrange("zkey", 0, -1));
		
    	 System.out.println(jedis.zrangeByScore("zkey", 0, 3));
    	 //返回有序集 key 中，指定区间内的成员。(从大到小)
         Set<String> setValues2 = jedis.zrevrange("zkey", 0, -1);
         Set<Tuple> zrangeWithScores = jedis.zrangeWithScores("zkey", 0, 4);
         System.out.println(zrangeWithScores.toString());*/
         
         jedis.zincrby("api", 1, "20123412");
       
         jedis.zincrby("apj", 1, "aa");
         jedis.zincrby("apj", 2, "bb");
         jedis.zincrby("apj", 4, "cc");
         jedis.zincrby("apj", 3, "dd");
         jedis.zincrby("apj", 12, "ee");
         jedis.zincrby("apj", 6, "ff");
         jedis.zincrby("apj", 7, "gg");
         jedis.zincrby("apj", 89, "hh");
         jedis.zincrby("apj", 34, "ii");
         jedis.zincrby("apj", 56, "jj");
         jedis.zincrby("apj", 100, "j0");
         Set<Tuple> zrangeWithScores = jedis.zrevrangeWithScores("apj11", 0, 9);
         System.out.println(zrangeWithScores.size());
         for (Tuple tuple : zrangeWithScores) {
        	 System.out.println(tuple.getElement()+":"+tuple.getScore());
			
		}
         
         jedis.zincrby("ap", 1, "aa");
         jedis.zincrby("ap", 99, "bb");
         jedis.zincrby("ap", 4, "cc");
         jedis.zincrby("ap", 3, "dd");
         jedis.zincrby("ap", 12, "ee");
         jedis.zincrby("ap", 6, "ff");
         jedis.zincrby("ap", 7, "gg");
         jedis.zincrby("ap", 89, "hh");
         jedis.zincrby("ap", 34, "ii");
         jedis.zincrby("ap", 56, "jj");
         jedis.zincrby("ap", 100, "j0");
         Set<Tuple> zrangeWithScores2 = jedis.zrangeWithScores("ap", 0, -1);
         for (Tuple tuple : zrangeWithScores2) {
        	 System.out.println(tuple.getElement()+":"+tuple.getScore());
			
		}
         
         jedis.hincrBy("count1", "21:23", 1);
         jedis.hincrBy("count1", "21:25", 2);
         jedis.hincrBy("count1", "21:12", 3);
         jedis.hincrBy("count1", "21:01", 4);
         List<Map<String,String>> resultMap=new ArrayList<Map<String,String>>();
         Map<String, String> hgetAll = jedis.hgetAll("count1");
         System.out.println(hgetAll.toString());
         resultMap.add(hgetAll);
         System.out.println(resultMap.toString());
         
         List<Map<String,String>> resultMap1=new ArrayList<Map<String,String>>();
         for(int i=0;i<10;i++) {
        	 Map<String,String> map=new HashMap<String,String>();
        	 map.put("aa", "66");
        	 map.put("bb", "11");
        	 map.put("cc", "44");
        	 map.put("dd", "33");
        	 map.put("ee", "22");
        	 resultMap1.add(map);
        	
         }
         System.out.println("=======================");
         System.out.println(resultMap1.toString());
         System.out.println("===============================");
         SimpleDateFormat sdf=new SimpleDateFormat("HH:mm");
         System.out.println(sdf.format(new Date()));
         
         
         
	}
     //
    
     //
     // Map<String, String> user = new HashMap<String, String>();
     // user.put("name","huangyuxuan");
     // user.put("age", "0.5");
     // user.put("sex","男");
     // jedis.hmset("user",user);

     //
     // List<String> rsmap = jedis.hmget("user", "name", "age","sex");
     // System.out.println(rsmap);
     //
     // jedis.hdel("user","age");
     // System.out.println(jedis.hmget("user", "age")); //因为删除了，所以返回的是null
     // System.out.println(jedis.hlen("user")); //返回key为user的键中存放的值的个数2
     // System.out.println(jedis.exists("user"));//是否存在key为user的记录 返回true
     // System.out.println(jedis.hkeys("user"));//返回map对象中的所有key
     // System.out.println(jedis.hvals("user"));//返回map对象中的所有value
     //
     // testStr();
     // testList();
     // testSet();

     // Iterator<String> iter=jedis.hkeys("user").iterator();
     // while (iter.hasNext()){
     // String key = iter.next();
     // System.out.println(key+":"+jedis.hmget("user",key));
     // }
 }

